package course.cmsc436.medicationmanager;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class NewUser extends Activity {
	
	public  final static String USER_FIRST_NAME ="userFirstName";
	public static final String USER_LAST_NAME ="userLastName";
	public static final String USER_NUMBER ="userNumber";
	public static final String DR_NAME ="physicianName";
	public static final String DR_NUMBER ="physicianNumber";

	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_new_user);
		
		final EditText first = (EditText) findViewById(R.id.UserFirstName);	
		final EditText last = (EditText) findViewById(R.id.UserLastName);
		final EditText number = (EditText) findViewById(R.id.UserPhoneNumber);
		final EditText physicianName = (EditText) findViewById(R.id.physicianName);
		final EditText physicianNumber = (EditText) findViewById(R.id.physicianNumber);
		
		//button for submit
		Button submitButton = (Button) findViewById(R.id.userSubmitButton);
		submitButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				//personal fields are required, toast displays if not
				if ( first.getText().toString().equals("") || last.getText().toString().equals("") || number.getText().toString().equals("")) {
					Toast msg = Toast.makeText(getApplicationContext(), "Please fill out all personal information fields.", Toast.LENGTH_SHORT);
					msg.show();
				}
				else {
					//returns the data through intent
					Intent data = new Intent();
					data.putExtra(USER_FIRST_NAME, first.getText().toString());
					data.putExtra(USER_LAST_NAME, last.getText().toString());
					data.putExtra(USER_NUMBER, number.getText().toString());
					data.putExtra(DR_NAME , physicianName.getText().toString());
					data.putExtra(DR_NUMBER, physicianNumber.getText().toString());
					setResult(RESULT_OK, data);
					finish();
				}
			}
		});
	}



}
